package com.qiantu.phone.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.qiantu.phone.R;
import com.qiantu.phone.aop.Log;
import com.qiantu.phone.app.AppActivity;
import com.qiantu.phone.bean.AddDeviceBean;
import com.qiantu.phone.utils.AddDeviceParseUtil;

import java.util.List;

public class ControllerReplaceWifiActivity extends AppActivity {
    private TextView tvWifi;

    @Log
    public static void start(Context context, String serialNo, String controllerID, String name,String productModel) {
        Intent intent = new Intent(context, ControllerReplaceWifiActivity.class);
        intent.putExtra("serialNo", serialNo);
        intent.putExtra("controllerID", controllerID);
        intent.putExtra("name", name);
        intent.putExtra("productModel",productModel);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_controller_replace_wifi;
    }

    @Override
    protected void initView() {
        tvWifi = findViewById(R.id.btn_wifi);
        setOnClickListener(R.id.btn_wifi,R.id.btn_wifi_config);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_wifi:
                ControllerReplaceActivity.start(this, getIntent().getStringExtra("serialNo"),getIntent().getStringExtra("controllerID"), getIntent().getStringExtra("name"),false,getIntent().getStringExtra("productModel"));
                break;
            case R.id.btn_wifi_config:
                gotoWifiConfigView();
                break;
        }
    }

    private void gotoWifiConfigView(){
        Intent intent = new Intent(getContext(), AddDevice2Activity.class);
        //是否要重新配网的标识  1
        intent.putExtra("addDeviceName", "1");
        intent.putExtra("productLinkType", 2);
        AddDeviceBean.DeviceConfigNetworkBean mDeviceConfigNetworkBean = null;
        //解析json文件
        List<AddDeviceBean> data = AddDeviceParseUtil.parseData(getContext());
        for (AddDeviceBean datum : data) {
            List<AddDeviceBean.DeviceConfigNetworkBean> distributionNetworkMethods = datum.getDistributionNetworkMethods();
            for (AddDeviceBean.DeviceConfigNetworkBean distributionNetworkMethod : distributionNetworkMethods) {
                if(distributionNetworkMethod.getProductInfo().getProductModel().equals("0x1501")){
                    mDeviceConfigNetworkBean = distributionNetworkMethod;
                    break;
                }
            }
            if(mDeviceConfigNetworkBean != null){
                break;
            }
        }
        intent.putExtra("links",mDeviceConfigNetworkBean.getLinks());
        startActivity(intent);
    }
}
